141561f151e88aa55673ce43dceebca0b865f7df,src/main/java/com/emc/vipr/sync/target/AtmosTarget.java,AtmosTarget,filter,#SyncObject#,142
Before Change
ck.update(bs.getBuffer(), bs.getOffset(), bs.getSize());
Range r = new Range(read, read + c - 1);
final UpdateObjectRequest request = new UpdateObjectRequest();
request.identifier(id).acl(getAtmosAcl(obj.getMetadata())).content(bs).range(r);
request.setUserMetadata(umeta.values());
request.contentType(obj.getMetadata().getContentType()).wsChecksum(ck);
time(new Timeable<Object>() {
@Override
public Object call() {
atmos.updateObject(request);
return null;
}
}, OPERATION_UPDATE_OBJECT_FROM_SEGMENT);
}
read += c;
}
} else {
final CreateObjectRequest request = new CreateObjectRequest();
request.identifier(destPath).acl(getAtmosAcl(obj.getMetadata())).content(in);
request.setUserMetadata(umeta.values());
request.contentLength(obj.getSize()).contentType(obj.getMetadata().getContentType());
id = time(new Timeable<ObjectId>() {
@Override
public ObjectId call() {
return atmos.createObject(request).getObjectId();
}
}, OPERATION_CREATE_OBJECT_FROM_STREAM_ON_PATH);
}
}
updateRetentionExpiration(obj, id);
} finally {
if (in != null) {
in.close();
}
}
} else {
checkUpdate(obj, destPath, destMeta);
}
}
} else {
// Object Space
// don't create objects in objectspace with no data (likely directories from a filesystem source)
// note that files/objects with zero size are still considered to have data.
// TODO: is this a valid use-case (should we create these objects)?
if (!obj.hasData()) {
LogMF.debug(l4j, "Source {0} is not a data object, but target is in objectspace, ignoring",
obj.getSourceIdentifier());
return;
}
InputStream in = null;
try {
ObjectId id = null;
// Check and see if a target ID was alredy computed
String targetId = obj.getTargetIdentifier();
if (targetId != null) {
id = new ObjectId(targetId);
}
if (id != null) {
ObjectMetadata destMeta = getMetadata(id);
if (destMeta == null) {
// Target ID not found!
throw new RuntimeException("The target object ID " + id + " was not found!");
}
obj.setTargetIdentifier(id.toString());
checkUpdate(obj, id, destMeta);
} else {
in = obj.getInputStream();
if (in == null) {
// Usually some sort of directory
final CreateObjectRequest request = new CreateObjectRequest();
request.acl(getAtmosAcl(obj.getMetadata())).contentType(obj.getMetadata().getContentType());
request.setUserMetadata(umeta.values());
id = time(new Timeable<ObjectId>() {
@Override
public ObjectId call() {
return atmos.createObject(request).getObjectId();
}
}, OPERATION_CREATE_OBJECT);
} else {
if (checksum != null) {
final RunningChecksum ck = new RunningChecksum(ChecksumAlgorithm.valueOf(checksum));
byte[] buffer = new byte[1024 * 1024];
long read = 0;
int c;
while ((c = in.read(buffer)) != -1) {
final BufferSegment bs = new BufferSegment(buffer, 0, c);
if (read == 0) {
// Create
ck.update(bs.getBuffer(), bs.getOffset(), bs.getSize());
final CreateObjectRequest request = new CreateObjectRequest();
request.acl(getAtmosAcl(obj.getMetadata())).content(bs);
request.setUserMetadata(umeta.values());
request.contentType(obj.getMetadata().getContentType()).wsChecksum(ck);
id = time(new Timeable<ObjectId>() {
@Override
public ObjectId call() {
return atmos.createObject(request).getObjectId();
}
}, OPERATION_CREATE_OBJECT_FROM_SEGMENT);
} else {
// Append
ck.update(bs.getBuffer(), bs.getOffset(), bs.getSize());
Range r = new Range(read, read + c - 1);
final UpdateObjectRequest request = new UpdateObjectRequest();
request.identifier(id).acl(getAtmosAcl(obj.getMetadata())).content(bs).range(r);
request.setUserMetadata(umeta.values());
request.contentType(obj.getMetadata().getContentType()).wsChecksum(ck);
time(new Timeable<Void>() {
@Override
public Void call() {
After Change
ck.update(bs.getBuffer(), bs.getOffset(), bs.getSize());
Range r = new Range(read, read + c - 1);
final UpdateObjectRequest request = new UpdateObjectRequest();
request.identifier(id).content(bs).range(r).wsChecksum(ck);
request.contentType(obj.getMetadata().getContentType());
time(new Timeable<Object>() {
@Override
public Object call() {
atmos.updateObject(request);
return null;
}
}, OPERATION_UPDATE_OBJECT_FROM_SEGMENT);
}
read += c;
}
} else {
final CreateObjectRequest request = new CreateObjectRequest();
request.identifier(destPath).acl(getAtmosAcl(obj.getMetadata())).content(in);
request.setUserMetadata(umeta.values());
request.contentLength(obj.getMetadata().getSize()).contentType(obj.getMetadata().getContentType());
id = time(new Timeable<ObjectId>() {
@Override
public ObjectId call() {
return atmos.createObject(request).getObjectId();
}
}, OPERATION_CREATE_OBJECT_FROM_STREAM_ON_PATH);
}
}
updateRetentionExpiration(obj, id);
} finally {
if (in != null) {
in.close();
}
}
} else {
checkUpdate(obj, destPath, destMeta);
}
}
} else {
// Object Space
// don't create directories in objectspace
// TODO: is this a valid use-case (should we create these objects)?
if (obj.isDirectory()) {
LogMF.debug(l4j, "Source {0} is a directory, but target is in objectspace, ignoring",
obj.getSourceIdentifier());
return;
}
InputStream in = null;
try {
ObjectId id = null;
// Check and see if a target ID was alredy computed
String targetId = obj.getTargetIdentifier();
if (targetId != null) {
id = new ObjectId(targetId);
}
if (id != null) {
ObjectMetadata destMeta = getMetadata(id);
if (destMeta == null) {
// Target ID not found!
throw new RuntimeException("The target object ID " + id + " was not found!");
}
obj.setTargetIdentifier(id.toString());
checkUpdate(obj, id, destMeta);
} else {
in = obj.getInputStream();
if (in == null) {
// Usually some sort of directory
final CreateObjectRequest request = new CreateObjectRequest();
request.acl(getAtmosAcl(obj.getMetadata())).contentType(obj.getMetadata().getContentType());
request.setUserMetadata(umeta.values());
id = time(new Timeable<ObjectId>() {
@Override
public ObjectId call() {
return atmos.createObject(request).getObjectId();
}
}, OPERATION_CREATE_OBJECT);
} else {
if (checksum != null) {
final RunningChecksum ck = new RunningChecksum(ChecksumAlgorithm.valueOf(checksum));
byte[] buffer = new byte[1024 * 1024];
long read = 0;
int c;
while ((c = in.read(buffer)) != -1) {
final BufferSegment bs = new BufferSegment(buffer, 0, c);
if (read == 0) {
// Create
ck.update(bs.getBuffer(), bs.getOffset(), bs.getSize());
final CreateObjectRequest request = new CreateObjectRequest();
request.acl(getAtmosAcl(obj.getMetadata())).content(bs);
request.setUserMetadata(umeta.values());
request.contentType(obj.getMetadata().getContentType()).wsChecksum(ck);
id = time(new Timeable<ObjectId>() {
@Override
public ObjectId call() {
return atmos.createObject(request).getObjectId();
}
}, OPERATION_CREATE_OBJECT_FROM_SEGMENT);
} else {
// Append
ck.update(bs.getBuffer(), bs.getOffset(), bs.getSize());
Range r = new Range(read, read + c - 1);
final UpdateObjectRequest request = new UpdateObjectRequest();
request.identifier(id).content(bs).range(r).wsChecksum(ck);
request.contentType(obj.getMetadata().getContentType());
time(new Timeable<Void>() {
@Override
public Void call() {